package com.hopu.computer;

import com.hopu.computer.annotation.MyComponent;
import com.hopu.computer.annotation.MyValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 电脑类
 */
@Component
public class Computer {

    /**
     * 型号
     */
//    @Value("小米999")
    @MyValue(value = "小米1001")
    private String type;

    /**
     * cpu依赖
     */
//    @Resource(name="AMDCpu")
    @MyComponent(AMDCpu.class)
    private ICpu cpu;

    /**
     * memory依赖
     */
//    @Resource(name="kingstonMemory")
    @MyComponent(KingstonMemory.class)
    private IMemory memory;

    public Computer(String type, ICpu cpu, IMemory memory) {
        this.type = type;
        this.cpu = cpu;
        this.memory = memory;
        System.out.println("调用了有参的构造方法");
    }

    public Computer() {
        System.out.println("调用了无参的构造方法");
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public ICpu getCpu() {
        return cpu;
    }

    public void setCpu(ICpu cpu) {
        this.cpu = cpu;
    }

    public IMemory getMemory() {
        return memory;
    }

    public void setMemory(IMemory memory) {
        this.memory = memory;
    }

    /**
     * 运行
     */
    public void start(){
        System.out.println("型号：" + type + "的电脑运行起来了！");
        cpu.run();
        memory.read();
        memory.write();
    }

    public void init(){
        System.out.println("电脑初始化了！！");
    }

    public void destroy(){
        System.out.println("电脑销毁了！");
    }
}
